package com.example.park2301.utils

import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.Observer
import java.util.concurrent.atomic.AtomicBoolean

class SingLiveData<T>:MediatorLiveData<T> (){
    private var falg =AtomicBoolean(false)
    override fun observe(owner: LifecycleOwner, observer: Observer<in T>) {
        super.observe(owner){
            if (falg.compareAndSet(true,false)){
                observer.onChanged(it)
            }
        }
    }

    override fun setValue(value: T) {
        falg.set(true)
        super.setValue(value)
    }
}